﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DBManager.DanhMucHeThong.BAL;
namespace MamNonTuoiTho.Form.QuanLyHocSinh
{
    public partial class frmHuyen : DevComponents.DotNetBar.Office2007Form
    {
        public frmHuyen()
        {
            InitializeComponent();
            Huyen_Load();
        }
        #region LoadData
        private void Huyen_Load()
        {
            grvHuyen.AutoGenerateColumns = false;
            grvHuyen.DataSource= DanhMuc_BAL.DanhMuc_GetItems("Huyen");
        }
        #endregion LoadData

        private void cmdThem_Click(object sender, EventArgs e)
        {
            try
            {
                frmHuyen_Edit Huyen_Edit = new frmHuyen_Edit();
                Huyen_Edit.FormClosed += new FormClosedEventHandler(Huyen_Edit_FormClosed);
                Huyen_Edit.Show();
            }
            catch (Exception)
            {                
                throw;
            }
        }

        void Huyen_Edit_FormClosed(object sender, FormClosedEventArgs e)
        {
            Huyen_Load();
        }

        private void cmdChinhSua_Click(object sender, EventArgs e)
        {
            try
            {
                int DanhMucID = int.Parse(grvHuyen.SelectedRows[0].Cells["DanhMucID"].Value.ToString());
                frmHuyen_Edit Huyen_Edit = new frmHuyen_Edit();
                Huyen_Edit.DanhMucID = DanhMucID;
                Huyen_Edit.Huyen_Load();
                Huyen_Edit.FormClosed += new FormClosedEventHandler(Huyen_Edit_FormClosed);
                Huyen_Edit.Show();
            }
            catch (Exception)
            {                
                throw;
            }
        }

        private void cmdXoa_Click(object sender, EventArgs e)
        {
            int DanhMucID = int.Parse(grvHuyen.SelectedRows[0].Cells["DanhMucID"].Value.ToString());
            DialogResult result = MessageBoxEx.Show("Bạn muốn xoá mục này?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
            if (result==DialogResult.Yes)
            {
                DanhMuc_BAL.DanhMuc_Delete(DanhMucID);
                Huyen_Load();
            }
        }
    }
}